const {defineConfig} = require('@vue/cli-service');
const path = require('path'),
	resolve = dir => path.resolve(__dirname, dir),
	IS_PROD = ['production', 'prod'].includes(process.env.NODE_ENV);
module.exports = defineConfig({
	publicPath: './',
	transpileDependencies: true,
	lintOnSave: false,       // 关闭eslint校验
	chainWebpack: config => {
		config.entry.app = ['babel-polyfill', './src/main.js'];
		// 修复HMR
		config.resolve.symlinks(true);
		//修复 Lazy loading routes Error
		config.plugin('html').tap(args => {
			args[0].chunksSortMode = 'none';
			return args;
		});
		// 添加别名
		config.resolve.alias
			.set('@', resolve('src'))
			.set('assets', resolve('src/assets'))
			.set('components', resolve('src/components'))
			.set('pages', resolve('src/pages'))
			.set('style', resolve('src/style'));
	},

	pluginOptions: {
		// 配置全局通用less变量
		"style-resources-loader": {
			preProcessor: "less",
			patterns: [
				path.resolve(__dirname, "./src/style/common/base.less"),
			],
		},
	},
	configureWebpack: config => {
		if (IS_PROD) {
			const plugins = [];

			config.output.filename =`js/[name].[contenthash:8].js?v=${new Date().getTime()}`;
			config.output.chunkFilename =`js/[name].[contenthash:8].js?v=${new Date().getTime()}`;
			config.plugins = [
				...config.plugins,
				...plugins
			];
		}
	},
	devServer: {
		open: '/',
		port: 8080,
	},
})
